#-*- coding:utf-8 -*-
import logging

# 默认的日志输出级别为 warning

# 修改默认输出级别, 输出到文件 、写入文件为覆盖
# logging.basicConfig(level = logging.DEBUG,filename = 'demo.log',filemode = 'w')
# logging.basicConfig(level = logging.DEBUG,
#                     format = '%(asctime)s | %(filename)s: %(lineno)s | %(message)s',
#                     datefmt = '%Y-%m-%d')

# logging.debug("this is a debug")
# logging.info("this is a info")
# logging.warning("this is a warning")
# logging.error("this is a error")
# logging.critical("this is a critical")

# name = '张三'
# age = 18
# logging.debug("姓名：%s,年龄：%d",name,age)
# logging.debug("姓名：%s,年龄：%d"%(name,age))
# logging.debug("姓名：{},年龄：{}".format(name,age))





# 创建一个记录器
logger = logging.getLogger("dqzz.app.log")
logger.setLevel(logging.INFO) # 设置等级

# 创建标准输出处理器
sh = logging.StreamHandler() # 标准输出
sh.setLevel(logging.WARNING)
# 创建文件处理器
fh = logging.FileHandler(filename="applog.log",mode="w")

# 创建格式器 
formatter = logging.Formatter("%(asctime)s | %(levelname)s | %(filename)s: %(lineno)s | %(message)s")
sh.setFormatter(formatter)
fh.setFormatter(formatter)

# 2 FileHandler("applog.log")   
# 3 RotatingFileHandler 多日志多文件的输出，按照文件的大小
# 4 TimeRotatingFileHandler 多日志多文件的输出，按照时间输出

# 记录器绑定处理器
logger.addHandler(sh)
logger.addHandler(fh)

# 创建过滤器
flt = logging.Filter("dqzz")
# 记录器添加过滤器
logger.addFilter(flt)
# # 处理器添加过滤器
# sh.addFilter(flt)

logger.debug("this is a debug")
logger.info("this is a info")
logger.warning("this is a warning")
logger.error("this is a error")
logger.critical("this is a critical")